/*
 * Copyright (c) 2017 Solidwang. All Rights Reserved
 */
package com.solid4j.auth.service.impl;

import com.solid4j.auth.dao.BaseDao;
import com.solid4j.auth.model.Privilege;
import com.solid4j.auth.page.Page;
import com.solid4j.auth.service.PageService;
import com.solid4j.auth.service.PrivilegeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: chengfeng
 * @date: 2017/5/4
 */
@Component("privilegeService")
public class PrivilegeServiceImpl implements PrivilegeService {
    @Resource
    private BaseDao<Privilege> baseDao;

    @Resource
    private PageService pageService;

    private Page<Privilege> page;

    @Override
    public Integer save(Privilege privilege) {
        return baseDao.save(privilege);
    }

    @Override
    public Privilege get(Integer id) {
        return baseDao.get(Privilege.class, id);
    }

    @Override
    public Page<Privilege> getPrivilegeList(String condition, Integer currentPage, Integer pageSize, String orderBy) {
        if (page == null)
            page = new Page<Privilege>();
        page.setObjName("Privilege");
        page.setCondition(condition);
        page.setOrderBy("id desc");
        page.setCurrentPage(currentPage);
        page.setPageSize(pageSize);
        page = pageService.queryObjList(page);
        return page;
    }

    @Override
    public List<Privilege> getPrivileges() {
        List<Privilege> list = new ArrayList<Privilege>();
        try {
            String hql = "from Privilege";
            list = baseDao.getList(hql);
            return list;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public void update(Privilege privilege) {
        baseDao.update(privilege);
    }

    @Override
    public void delete(Privilege privilege) {
        baseDao.delete(privilege);
    }
}
